package cn.com.zpark.filter.servlet;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @PackageName: cn.com.zpark.filter.servlet
 * @ClassName: ServletFilterDemo03
 * @Description:
 * @author: RZS
 * @date: 2021/11/17  17:41
 */
@WebServlet("/user/login.do")
public class ServletFilterDemo03 extends HttpServlet {
    @Override
    protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String name = request.getParameter("name");
        System.out.println(name);
        if("张三".equals(name)){
            // 登录成功
            request.getSession().setAttribute("name", name);
            request.getRequestDispatcher("/user/login/success.do").forward(request, response);
        }else{
            response.getWriter().write("<h1>登录失败</h1>");
        }
    }
}
